//
//  Float+Extension.swift
//  FrameProduct
//
//  Created by delegate on 2024/2/3.
//

import Foundation

extension Float: LXSExtensionCompatible {}
extension Double: LXSExtensionCompatible {}
extension Int: LXSExtensionCompatible {}

public extension LXS where Base == Float {
    /// 小数点后如果只是0，显示整数，如果不是，显示原来的值
    /// 使用 truncatingRemainder 方法进行浮点数取余
     var cleanZero : String {
        return base.truncatingRemainder(dividingBy: 1) == 0 ? String(format: "%.0f", base) : String(base)
    }
}

public extension LXS where Base == Double {
    /// 小数点后如果只是0，显示整数，如果不是，显示原来的值
    /// 使用 truncatingRemainder 方法进行浮点数取余
    var cleanZero : String {
        return base.truncatingRemainder(dividingBy: 1) == 0 ? String(format: "%.0f", base) : String(base)
    }
}

public extension LXS where Base == Int {
    // MARK: - Int保留多少位 默认为2
    func keepInt(_ digits:Int = 2) -> String {
        let formatter = NumberFormatter()
        formatter.minimumIntegerDigits = digits
        return formatter.string(for: base) ?? ""
    }
}



/*
 2，如果要保留两位小数

 var f = 123.123121313

 var s = String(format:"%.2f",f)//123.32

 3，int类型,不足2位前面补0

 var f = 3

 var s = String(format:"%02d",f)//03
 */
